package com.itheima.stock.controller;

import com.itheima.stock.common.domain.*;
import com.itheima.stock.pojo.*;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Api(tags = "股票")
@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Autowired
    private StockService stockService;

    /**
     *需求说明: 沪深两市板块分时行情数据查询，以交易时间和交易总金额降序查询，取前10条数据
     * @return
     */
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> sectorAll(){
        return stockService.sectorAllLimit();
    }

    /**
     * 获取国内最新大盘指数
     * @return
     */
    @ApiOperation(value="国内大盘指数")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> innerIndexAll(){
        return stockService.innerIndexAll();
    }

    /**
     * 获取国外最新大盘指数
     * @return
     */
    @ApiOperation(value="国外大盘指数")
    @GetMapping("/external/index")
    public R<List<OuterMarketDomain>> outerIndexAll(){
        return stockService.outerIndexAll();
    }


    @GetMapping("/stock/business/all")
    public List<StockBusiness> getAllBusiness(){
        return stockService.getAllStockBusiness();
    }

    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> stockIncreaseLimit(){
        return stockService.stockIncreaseLimit();
    }

    @GetMapping("/stock/all")
    public R<PageResult<StockUpdownDomain>> stockPage(Integer page, Integer pageSize){
        return stockService.stockPage(page, pageSize);
    }

    @GetMapping("/stock/updown/count")
    public R<Map> upDownCount(){
        return stockService.upDownCount();
    }

    @GetMapping("/stock/export")
    public void stockExport(HttpServletResponse response, Integer page, Integer pageSize){
        stockService.stockExport(response,page,pageSize);
    }

    @GetMapping("/stock/tradevol")
    public R<Map> stockTradeVol4InnerMarket(){
        return stockService.stockTradeVol4InnerMarket();
    }

    @GetMapping("/stock/updown")
    public R<Map> getStockUpDown(){
        return stockService.stockUpDownScopeCount();
    }

    @ApiOperation(value = "分时查询")
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> stockScreenTimeSharing(String code){
        return stockService.stockScreenTimeSharing(code);
    }

    @ApiOperation(value = "个股日K线")
    @RequestMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getDayKLinData(@RequestParam("code") String stockCode){
        return stockService.stockCreenDkLine(stockCode);
    }

    @ApiOperation(value = "个股周K线")
    @GetMapping("/stock/screen/weekkline")
    public R<List<StockWeekK>> getWeekKLineData(String code) {
        return stockService.stockWeekK(code);
    }

    /**
     * 联想查询
     */
    @ApiOperation(value = "联想查询")
    @GetMapping("/stock/search")
    public R<List<StockCodeLenovo>> getStockNameByCode(String searchStr) {
        return stockService.stockNameByCode(searchStr);
    }

    /**
     * 个股信息描述
     * @param code
     * @return
     */
    @ApiOperation(value = "个股信息描述")
    @GetMapping("/stock/describe")
    public R<StockDescribe> getStockDescribe(String code) {
        return stockService.stockDescribe(code);
    }

    /**
     * 个股最新分时详情
     * @param code
     * @return
     */
    @ApiOperation(value = "个股最新分时详情")
    @GetMapping("/stock/screen/second/detail")
    public R<StockNewTimeShare> getStockNewTimeShare(String code) {
        return stockService.getStockNew(code);
    }

    /**
     * 个股实时交易流水查询功能
     */
    @ApiOperation(value = "个股实时交易流水查询功能")
    @GetMapping("/stock/screen/second")
    public R<List<StockTimeTransaction>> getStockRealTimeTransaction(String code) {
        return stockService.getStockTimeTransaction(code);
    }

}
